﻿#pragma strict

var item_Pictures : Texture2D[]; 
var item_Price : String[];
var item_Disc : String[];
var Tab = 0;
var TabNames : String[] = ["Maquinas", "Terreno", "Funcionario"];
var scrollPosition : Vector2 = Vector2.zero;
var items : GameObject[];
var Shop : GameObject;
var Shop_Open : boolean = false;
var Shop_Range : float = 100;
var toolbar : int;
var auxComprar : int = -1;
var maquina : GameObject;
var mousePos:Vector3;
private var object : GameObject;
 
function Start(){
    items = new GameObject[3];
}
 
 
//buy menu
function Maquinas () {
    scrollPosition = GUI.BeginScrollView (Rect(20, 20, items.Length * 150, 600), scrollPosition, Rect (0, 0, 100, 700));
 
    for (var i = 0; i < items.length; i++) {
       GUI.BeginGroup(Rect(0, i * 120, 450, 120));
       GUI.Box(Rect(0, 0, 450, 120), "");
       GUI.Box(Rect(15, 15, 120, 100), item_Pictures[i]);
       //GUI.Box(Rect(15, 145, 155, 75), item_Disc[i]);
       GUI.Label(Rect(50, 90, 500, 250), "R$" + item_Price[i]);
       if(GUI.Button(Rect(360,50,65,30),"Comprar"))
       		auxComprar = i;//Botao Comprar 
       GUI.EndGroup();
    }
 	GUI.EndScrollView();
 	
	if(auxComprar == 1 && !Maquina.seguindo)
	{
		if(GUIgeral.dinheiro >= float.Parse(item_Price[1],System.Globalization.CultureInfo.InvariantCulture.NumberFormat))
		{		
		    GUIgeral.dinheiro = GUIgeral.dinheiro - float.Parse(item_Price[1],System.Globalization.CultureInfo.InvariantCulture.NumberFormat);		    
		    var maquina = Instantiate(maquina,mousePos,Quaternion.identity);
		    //comprado=true;
		    object = maquina;
		    Maquina.object = maquina;
		    Maquina.Seguir();
		}
		else
		{
			Debug.Log("Nao tem dinheiro suficiente");
		}
		auxComprar = -1;
		Shop_Open= false;
	}
}
 
 
//sell menu
function Terreno () {
    //too be added
}
 
 
//repair menu
function Funcionarios() {
    //too be added
}
 
 
 
function theFirstMenu() {
    toolbar = GUI.Toolbar (Rect(Screen.width / 2 - 300, 25, 280, 30), Tab, TabNames);
    
    //basic shop menu shtuff
    GUI.BeginGroup(Rect(Screen.width / 2 - 300, 55, 500, 400));
    GUI.Box(Rect(0, 0, 500, 400), "");
 
    switch (Tab) {
        case 0:
           Maquinas();
           break;
        case 1:
           Terreno();
           break;
        case 2:
           Funcionarios();
           break;
    }
    GUI.EndGroup();
}

function OnGUI () {
    if(GUI.Button(Rect(Screen.width-70,0,70,30),"LOJA"))
    {
        Shop_Open = true;
    }
    
    if (Shop_Open == true)
    {
		//toolbar = GUI.Toolbar (Rect(Screen.width / 2 - 300, 25, 200, 30), Tab, TabNames);
        if(GUI.Button(Rect(Screen.width / 2 + 170, 25, 30, 30), "X"))
    	{
    		Shop_Open = false;
    	}
    	theFirstMenu();
    }
    
}
 
 
function Update () {
    
}